<template>
    <div class="scoll-top" @click="backTop" v-if="showTop">
        <i class="el-icon-caret-top" color="var(--themeColor)"></i>
    </div>
</template>
<script>
export default {
    name: 'ScollTop',
    data() {
        return {
            showTop: false
        }
    },
    mounted() {
        this.handleScroll();
        window.addEventListener('scroll', this.handleScroll);
    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll);
    },
    methods: {
        handleScroll() {
            this.showTop = document.documentElement.scrollTop > 200 ? true : false;
        },
        backTop() {
            window.scrollTo({
                top: 0,
                behavior: "smooth"
            });
        }
    }
}
</script>
<style lang="scss" scoped>
.scoll-top {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 40px;
    height: 40px;
    background-color: #fff;
    border-radius: 50%;
    box-shadow: 0 4px 8px 6px rgba(7, 17, 21, 0.06);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 9;

    i {
        font-size: 20px;
    }

    &:hover {
        box-shadow: 0 4px 8px 10px rgba(7, 17, 21, 0.1);
    }
}
</style>